import Vue from "vue";
import Router from "vue-router";

Vue.use(Router);
import Layout from "../views/layout/layout";

export default new Router({
  routes: [
    //登录
    {
      path: "/login",
      // component: () => import("@/views/login/index"),
      component: r =>
        require.ensure([], () => r(require("@/views/login/index"), "login")),
      hidden: true
    },
    //404
    {
      path: "/404",
      // component: () => import("@/views/404"),
      component: r =>
        require.ensure([], () => r(require("@/views/404"), "404")),
      hidden: true
    },
    //首页
    {
      path: "/",
      component: Layout,
      redirect: "/home",
      name: "Home",
      hidden:true,
      children: [
        {
          path: "home",
          // component: () => import("@/views/home/index"),
          component: r =>
            require.ensure([], () => r(require("@/views/home/index"), "home")),
          meta: { title: "Home", needLogin: true }
        }
      ]
    },
    //charts
    {
      path: "/charts",
      component: Layout,
      redirect: "/charts/pieChart",
      name: "charts",
      meta: { title: "图表" },
      children: [
        {
          path: "/charts/pieChart",
          name: "pieChart",
          // component: () => import("@/views/charts/pieChart"),
          component: r =>
            require.ensure([], () =>
              r(require("@/views/charts/pieChart"), "charts")
            ),
          meta: { title: "饼图", needLogin: true }
        },
        {
          path: "/charts/lineChart",
          name: "lineChart",
          // component: () => import("@/views/charts/lineChart"),
          component: r =>
            require.ensure([], () =>
              r(require("@/views/charts/lineChart"), "charts")
            ),
          meta: { title: "条形图", needLogin: true }
        }
      ]
    },
  ]
});


export const asyncRoutes = [
  //tables
  {
    path: "/tables",
    component: Layout,
    redirect: "/tables/normalTable",
    name: "tables",
    meta: { title: "表格" },
    children: [
      {
        path: "/tables/normalTable",
        name: "normalTable",
        // component: () => import("@/views/tables/normalTable"),
        component: r =>
          require.ensure([], () =>
            r(require("@/views/tables/normalTable"), "tables")
          ),
        meta: { title: "普通表格", needLogin: true }
      },
      // {
      //   path: "table1/edit",
      //   name: "table1Edit",
      //   // component: () => import("@/views/tables/table1Edit"),
      //   component: r =>
      //     require.ensure([], () =>
      //       r(require("@/views/tables/table1Edit"), "tables")
      //     ),
      //   meta: { title: "table1Edit", needLogin: true }
      // },
      {
        path: "/tables/complexTable",
        name: "complexTable",
        // component: () => import("@/views/tables/complexTable"),
        component: r =>
          require.ensure([], () =>
            r(require("@/views/tables/complexTable"), "tables")
          ),
        meta: { title: "功能表格", needLogin: true }
      }
    ]
  },
  //editor
  {
    path: "/editor",
    component: Layout,
    redirect: "/editor/jsonEditor",
    name: "editor",
    children: [
      {
        path: "/editor/jsonEditor",
        name: "jsonEditor",
        component: r =>
          require.ensure([], () =>
            r(require("@/views/editor/jsonEditor"), "editor")
          ),
        meta: { title: "jsonEditor", needLogin: true }
      },
      {
        path: "/editor/markdown",
        name: "markdown",
        component: r =>
          require.ensure([], () =>
            r(require("@/views/editor/markdown"), "editor")
          ),
        meta: { title: "markdown", needLogin: true }
      }
    ]
  }
]